$(function(){
    var $alter_student=$(".alter_student")/*确定添加学生按钮*/,
        $stu_name=$("#stu_name")/*学生姓名输入框*/,
        $stu_sex=$("#stu_sex")/*学生性别下拉框*/;


    //判断名字是中文
    var checkNameRight=function(name){
        var myReg = /^[\u4e00-\u9fa5]+$/;
        if (myReg.test(name)){
            return true;
        } else {
            return false;;
        }
    };
    var check=function(){
        var _name = $.trim($stu_name.val())
        var error={
            haserror:false,
            errormsg:""
        };
        if(_name.length>5||_name.length<2){
            error={
                haserror:true,
                errormsg:"姓名长度为2-5个汉字"
            };
        }else if (!checkNameRight(_name)){
            error={
                haserror:true,
                errormsg:"姓名长度为2-5个汉字"
            };
        }
        return error;
    };

    $alter_student.click(function(){
        var error=check();
        if(error.haserror)
        {
            layer.open({
                content:error.errormsg,
                title:"",
                time : 2,
                style: 'border:none; background-color:#222222; color:#fff;'
            });
        }else{
            var student={
                id:$stu_name.data().id,
                name:$stu_name.val(),
                sex:$stu_sex.val()

            };
            console.log(student)
            layer.open({
                content:"修改成功",
                title:"",
                time : 1,
                style: 'border:none; background-color:#222222; color:#fff;'
            });
        }
    });
});